/* * CSDN 登录框 * Copyright 2012, zhuhz@csdn.net * Date: 2012-6-6 * * 调用:csdn.showLogin(callback); * * 获取当前登录用户名(可用于判断用户是否处于登录状态):csdn.getCookie('UserName') */ var csdn = window.csdn || function () { }; csdn.domain = "passport.csdn.net"; csdn.doing = false; csdn.$ = function (id) { return document.getElementById(id); }; csdn.loginBack = null; csdn.showLogin = function (callback) { var div = document.createElement("DIV"); div.id = "csdn_divh"; //div.style.marginLeft = "-200px"; div.style.marginTop = -75 + (document.documentElement.scrollTop || document.body.scrollTop) + "px"; // var title = '登录[X]'; var title = ''; var body = csdn.loginForm(); var bottom = ''; var s = csdn.openBox().replace('#title#', title).replace('#body#', body); div.innerHTML = s; csdn.shieldBody(); document.body.appendChild(div); var un = csdn.getCookie("UN"); if (un) { csdn.$('u').value = un; csdn.$('p').focus(); } else { csdn.$('u').focus(); } csdn.$('u').onkeypress = csdn.$('p').onkeypress = function (ev) { if (csdn.isEnter(ev)) { csdn.login(); } }; csdn.loginBack = callback; }; csdn.closeLogin = function () { document.body.removeChild(csdn.$('csdn_divh')); document.body.removeChild(csdn.$('csdn_shield')); }; csdn.shieldBody = function () { var shield = document.createElement("DIV"); shield.id = "csdn_shield"; var h1 = document.documentElement.clientHeight; var h2 = document.documentElement.scrollHeight; shield.style.height = Math.max(h1, h2) + "px"; shield.style.filter = "alpha(opacity=0)"; shield.style.opacity = 0; document.body.appendChild(shield); csdn.setOpacity = function (obj, opacity) { if (opacity >= 1) opacity = opacity / 100; try { obj.style.opacity = opacity; } catch (err) { } try { if (obj.filters.length > 0 && obj.filters("alpha")) { obj.filters("alpha").opacity = opacity * 150; } else { obj.style.filter = "alpha(opacity=\"" + (opacity * 150) + "\")"; } } catch (err) { } }; var c = 0; csdn.doAlpha = function () { c += 2; if (c > 20) { clearInterval(ad); return 0; } csdn.setOpacity(shield, c); }; var ad = setInterval("csdn.doAlpha()", 1); }; csdn.setStyle = function () { var lk = document.createElement("LINK"); lk.type = "text/css"; lk.rel = "stylesheet"; lk.href = location.protocol + "//" + csdn.domain + "/content/loginbox/style.css?r=" + (new Date().getTime()); var head = document.getElementsByTagName("head")[0]; head.appendChild(lk); }; csdn.isEnter = function (ev) { ev = ev || window.event; var code = (ev.keyCode || ev.which); return (code == 10 || code == 13); }; csdn.getCookie = function (name) { var ck = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)")); if (ck) return ck[2]; else return null; }; csdn.setCookie = function (name, value, expires) { if (expires) expires = '; expires=' + new Date(expires).toUTCString(); else expires = ''; var path = '; path=/'; var domain = '; domain=' + document.domain.replace('www.', ''); document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain].join(''); } csdn.openBox = function () { var text = "